/*
 * @FileName: task.c
 * @Author: GreyQiu qiushaogui@aikosolar.com
 * @Date: 2023-08-08 16:34:29
 * @LastEditors: GreyQiu qiushaogui@aikosolar.com
 * @LastEditTime: 2023-09-26 11:43:56
 * @Description: 
 * 
 * Copyright (c) 2023, All Rights Reserved. 
 */

#include "easy_timer.h"
#include "bsp.h"
#include "dev_info.h"
#include "app_analog.h"
#include "app_fault.h"
#include "app_fsm.h"
#include "app_mppt.h"
#include "loop.h"

EASY_TIMER_DEF(timer_1ms);
EASY_TIMER_DEF(timer_10ms);
EASY_TIMER_DEF(timer_1000ms);

extern uint16_t g_vin_raw;
extern uint16_t g_iin_raw;
extern uint16_t g_vout_raw;

static void task_1000ms(void)
{
    bsp_gpio_toggle(LEG_GREEN_PIN); // 绿灯翻转
}

static void task_1ms(void)
{
    app_analog_run();
    app_fault_run();
    app_fsm_run();
    app_mppt_run();
}

static void task_10ms(void)
{

}


void task_init(void)
{
//    log_debug("optimizer demo start \n");
//    log_debug("device name: %s \n", g_device_info.devName);
//    log_debug("serial number: %s \n", g_device_info.serialNum);
//    log_debug("software version: 0x%04x \r\nbulid date: %s %s\r\n", g_device_info.swVer, __DATE__, __TIME__);
    loop_init();
    app_analog_init();
    app_fsm_init();

    // 1000ms任务
    easy_timer_create(timer_1ms);
    easy_timer_start(timer_1ms, 1, EASY_TIMER_MODE_REPEATED, task_1ms);

//    // 1000ms任务
//    easy_timer_create(timer_10ms);
//    easy_timer_start(timer_10ms, 5, EASY_TIMER_MODE_REPEATED, task_10ms);

    // 1000ms任务
    easy_timer_create(timer_1000ms);
    easy_timer_start(timer_1000ms, 1000, EASY_TIMER_MODE_REPEATED, task_1000ms);
}
